package com.renwei.yunlong.utils;

import android.content.Context;

import com.renwei.yunlong.YunLongApplication;
import com.renwei.yunlong.http.Api;
import com.renwei.yunlong.http.HttpPresenter;
import com.renwei.yunlong.http.HttpTaskListener;

import java.io.File;

/**
 * Project :  yunaandroid.
 * Package name: com.renwei.yunlong.utils
 * Created by :  Benjamin.
 * Created time: 2017/10/17 17:58
 * Changed by :  Benjamin.
 * Changed time: 2017/10/17 17:58
 * Class description:
 */

public class UploadManger {
    private static final UploadManger manager = new UploadManger();

    private UploadManger() {

    }

    public static UploadManger getManager() {
        return manager;
    }


    public void uploadIcon(Context context, File file, HttpTaskListener listener, String... params) {
        for (int i = 0; i < params.length; i++) {
            LogUtil.e("parameter" + params[i]);
        }
        LogUtil.e("parameter" + file.getAbsolutePath());
        LogUtil.e("parameter" + file.getName());
        HttpPresenter hp = new HttpPresenter(context);
        if ("1".equals(YunLongApplication.getCompanyType())) {
            hp.setUrl(Api.$().OWNER_FILE_URL + "/appUploadFile.htm");
        } else {
            hp.setUrl(Api.$().SERVICE_FILE_URL + "/appUploadFile.htm");
        }
        hp.setshowDialogcontent("文件正在上传...");
        hp.setRequsetId(999);
        hp.putParam("tempPath", "");
        hp.putParam("isControl", "1");
        hp.putParam("versionCode", params[0]);
        hp.putParam("companyCode", params[1]);
        hp.putParam("fileuploadFileName", file.getName());
        hp.putFile("fileupload", file);
        hp.setCallBack(listener);
        hp.post();
    }

    //上传用户资质证书图片
    public void uploadUserCertificate(Context context, File file, HttpTaskListener listener, String... params) {
        HttpPresenter hp = new HttpPresenter(context);
        if ("1".equals(YunLongApplication.getCompanyType())) {
            hp.setUrl(Api.$().OWNER_FILE_UPLOAD_URL);
            LogUtil.e("接口 uploadUserCertificate ------证件上传 \r\n Url :" + Api.$().OWNER_FILE_UPLOAD_URL + "\r\n 文件名称  :" + file.getName());
        } else {
            hp.setUrl(Api.$().SERVICE_FILE_UPLOAD_URL);
            LogUtil.e("接口 uploadUserCertificate ------证件上传 \r\n Url :" + Api.$().SERVICE_FILE_UPLOAD_URL + "\r\n 文件名称  :" + file.getName());
        }
        hp.putParam("versionCode", params[0]);
        hp.putParam("companyCode", params[1]);
        hp.putParam("fileuploadFileName", String.valueOf("个人证书" + System.currentTimeMillis()));
        hp.putParam("isControl", "0");
        hp.putFile("fileupload", file);
        hp.setshowDialogcontent("文件正在上传...");
        hp.setRequsetId(998);
        hp.setCallBack(listener);
        hp.post();
    }

    public void upEnterpriseCertificate(Context context, File file, HttpTaskListener listener) {
        HttpPresenter hp = new HttpPresenter(context);
        hp.setUrl(Api.$().MiDDLE_URL + "appUploadFile.htm");
        LogUtil.e("文件上传Url" + Api.$().MiDDLE_URL + "appUploadFile.htm  ————————文件名称" + file.getName());
        hp.setshowDialogcontent("文件正在上传...");
        hp.setRequsetId(998);
        hp.putParam("fileuploadFileName", file.getName());
        hp.putFile("fileupload", file);
        hp.setCallBack(listener);
        hp.post();
    }



    //意见反馈
    public void uploadFeedBackImage(Context context, File file, HttpTaskListener listener, String... params) {
        HttpPresenter hp = new HttpPresenter(context);
        if ("1".equals(YunLongApplication.getCompanyType())) {
            hp.setUrl(Api.$().OWNER_FILE_UPLOAD_URL);
            LogUtil.e("接口 uploadFeedBackImage ------证件上传 \r\n Url :" + Api.$().OWNER_FILE_UPLOAD_URL + "\r\n 文件名称  :" + file.getName());
        } else {
            hp.setUrl(Api.$().SERVICE_FILE_UPLOAD_URL);
            LogUtil.e("接口 uploadFeedBackImage ------证件上传 \r\n Url :" + Api.$().SERVICE_FILE_UPLOAD_URL + "\r\n 文件名称  :" + file.getName());
        }
        hp.putParam("versionCode", params[0]);
        hp.putParam("companyCode", params[1]);
        hp.putParam("fileuploadFileName", file.getName());
        hp.putParam("isControl", "0");
        hp.putFile("fileupload", file);
        hp.setshowDialogcontent("文件正在上传...");
        hp.setRequsetId(998);
        hp.setCallBack(listener);
        hp.post();
    }

}
